/*
day431 
2020.11.1 
*/
#include<iostream>
#include<cstring>
using namespace std;

class Solution {
public:
    string reverseOnlyLetters(string S) {
		int l=0,r=S.size()-1;
		char tem;
		while(l<r)
		{
			while(l<r && !isAl(S[l]))
			{
				++l;
			 } 
			while(l<r && !isAl(S[r])) 
			{
				--r;
			}
			
			if(l<r)
			{
				tem=S[l];
				S[l]=S[r];
				S[r]=tem;
			}
			l++;
			r--;
		}
		
		return S;
    }
    
    bool isAl(char c)
    {
    	return (c>='a' && c<='z') ||  (c>='A' && c<='Z');
	}
};


int main()
{
	string str="ab-cd";
	Solution s;
	cout<<s.reverseOnlyLetters(str);
	
	return 0;
}
